<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="https://unpkg.com/vue@3"></script>


<div id="counter">
    Counter: {{ counter }}
</div>

<div id="bind-attribute">
  <span v-bind:title="message">
    鼠标悬停几秒钟查看此处动态绑定的提示信息！
  </span>
</div>

<div id="event-handling">
    <p>{{ message }}</p>
    <button v-on:click="reverseMessage">反转 Message</button>
</div>

<div id="two-way-binding">
    <p>{{ message }}</p>
    <input v-model="message" />
</div>

<div id="conditional-rendering">
    <span v-if="seen">现在你看到我了</span>
</div>

<div id="list-rendering">
    <ol>
        <li v-for="todo in todos">
            {{ todo.text }}
        </li>
    </ol>
</div>
<script>

    const Counter = {
        data() {
            return {
                counter: 0
            }
        },
        mounted() {
            setInterval(() => {
                this.counter++
            }, 1000)
        }
    }

   var app =  Vue.createApp(Counter).mount('#counter')
    app.counter = 1


    const AttributeBinding = {
        data() {
            return {
                message: 'You loaded this page on ' + new Date().toLocaleString()
            }
        }
    }

    Vue.createApp(AttributeBinding).mount('#bind-attribute')

    const EventHandling = {
        data() {
            return {
                message: 'Hello Vue.js!'
            }
        },
        methods: {
            reverseMessage() {
                this.message = this.message
                    .split('')
                    .reverse()
                    .join('')
            }
        }
    }

    Vue.createApp(EventHandling).mount('#event-handling')

    const TwoWayBinding = {
        data() {
            return {
                message: 'Hello Vue!'
            }
        }
    }

    Vue.createApp(TwoWayBinding).mount('#two-way-binding')

    const ConditionalRendering = {
        data() {
            return {
                seen: true
            }
        }
    }

   var app1 =  Vue.createApp(ConditionalRendering).mount('#conditional-rendering')

    const ListRendering = {
        data() {
            return {
                todos: [
                    { text: 'Learn JavaScript' },
                    { text: 'Learn Vue' },
                    { text: 'Build something awesome' }
                ]
            }
        }
    }

    Vue.createApp(ListRendering).mount('#list-rendering')
</script>
</body>
</html>